package com.ruoyi.celoan.util;

import com.alibaba.fastjson2.JSONObject;
import com.google.common.collect.Lists;
import com.ruoyi.celoan.dto.EcDalianDataReportStatisticsDto;
import com.ruoyi.celoan.dto.ExTradeEffectFinancialproductsDetailDto;
import com.ruoyi.celoan.entity.*;
import com.ruoyi.celoan.request.*;
import com.xmsme.base.sdk.BaseApiClient;
import com.xmsme.base.sdk.request.AbstractApiRequest;
import com.xmsme.base.sdk.request.AreaStatistics;
import com.xmsme.base.sdk.request.ChangeAppSecretRequest;
import com.xmsme.base.sdk.request.StatisticsPostRequest;
import com.xmsme.base.sdk.response.ChangeAppSecretResponse;
import com.xmsme.base.sdk.response.StatisticsPostResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.format.DateTimeFormatter;
import java.util.List;

public class DataReportUtil {
    private static final Logger log = LoggerFactory.getLogger(DataReportUtil.class);

    public static StatisticsPostResponse dataReport(EcDalianDataReportStatisticsDto dto, BaseApiClient client) throws Exception {
        log.info(JSONObject.toJSONString(dto));
        DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        AreaStatistics item1 = AreaStatistics.builder().province(dto.getProvince()).city(dto.getCity()).areaCode(dto.getAreaCode()).registeredEnterpriseNum(dto.getRegisterEntNum()).creditEnterpriseNum(dto.getCreditEntNum()).loanEnterpriseNum(dto.getLoanEntNum()).creditLoanEnterpriseNum(dto.getLoanEntCrdNum()).financingNeedsEnterpriseNum(dto.getFinancingNeedsEntNum()).creditAmount(dto.getCreditAmt()).creditNum(dto.getCreditNum()).loanAmount(dto.getLoanAmt()).loanNum(dto.getLoanNum()).creditLoanAmount(dto.getLoanCrdAmt()).creditLoanNum(dto.getLoanCrdNum()).financingNeedsAmount(dto.getFinancingNeedsAmt()).financingNeedsNum(dto.getFinancingNeedsNum()).dockingNum(dto.getOrderBuildingNum()).overdueNum(dto.getOverdueNum()).averageLendingRate(dto.getAvgLoanRate()).fullBusinessProcessAveragePeriod(dto.getAvgBussDays()).creditAveragePeriod(dto.getAvgCreditDays()).loanAveragePeriod(dto.getAvgLoanDays()).creditLoanAveragePeriod(dto.getAvgLoanCrdDays()).nearlyYearLoanAmount(dto.getLoanAmtYear()).nearlyYearLoanNum(dto.getLoanNumYear()).nearlyYearLoanEnterpriseNum(dto.getLoanEntYear()).nearlyYearCreditLoanAmount(dto.getLoanCrdAmtYear()).nearlyYearCreditLoanNum(dto.getLoanCrdNumYear()).nearlyYearCreditLoanEnterpriseNum(dto.getLoanCrdEntYear()).nearlyYearFinancingNeedsAmount(dto.getFinancingNeedsAmtYear()).nearlyYearFinancingNeedsNum(dto.getFinancingNeedsNumYear()).settledInFinancialInstitutionNum(dto.getOrgNum()).financialProductsNum(dto.getProductNum()).externalSystemId("").statisticsBeginTime(format.format(dto.getStatStartTime())).statisticsEndTime(format.format(dto.getStatEndTime())).build();
        StatisticsPostRequest request = new StatisticsPostRequest(Lists.newArrayList(item1));
        StatisticsPostResponse response = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        log.info("post statistics {}", response);
        return response;
    }

    public static String userUpdate(BaseApiClient client, String appId, String appKey, String appSecret) throws Exception {
        System.out.println("用户修改密码");
        ChangeAppSecretRequest request = new ChangeAppSecretRequest(appId, appKey, appSecret);
        ChangeAppSecretResponse response = (ChangeAppSecretResponse) client.execute((AbstractApiRequest) request);
        log.info("post ChangeAppSecretRequest {}", response);
        return response.getAppSecret();
    }

    public static StatisticsPostResponse enterprises(List<ExTradeEffectEnterprisesDetailEntity> list, BaseApiClient client) throws Exception {
        EnterprisesUploadRequest request = new EnterprisesUploadRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse financingRequirements(List<ExTradeEffectFinancingrequirementsDetailEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectFinancingrequirementsDetailRequest request = new ExTradeEffectFinancingrequirementsDetailRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse institutionsStatistics(List<ExTradeEffectInstitutionsstatisticsSummaryEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectInstitutionsstatisticsSummaryRequest request = new ExTradeEffectInstitutionsstatisticsSummaryRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse financialInstitutions(List<ExTradeEffectFinancialinstitutionsDetailEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectFinancialinstitutionsDetailRequest request = new ExTradeEffectFinancialinstitutionsDetailRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse financialProducts(List<ExTradeEffectFinancialproductsDetailDto> list, BaseApiClient client) throws Exception {
        ExTradeEffectFinancialproductsDetailRequest request = new ExTradeEffectFinancialproductsDetailRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse policies(List<ExTradeEffectPoliciesDetailEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectPoliciesDetailRequest request = new ExTradeEffectPoliciesDetailRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse creditServiceAgencies(List<ExTradeEffectCreditserviceagenciesDetailEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectCreditserviceagenciesDetailRequest request = new ExTradeEffectCreditserviceagenciesDetailRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }

    public static StatisticsPostResponse creditProductStatistics(List<ExTradeEffectCreditproductstatisticsSummaryEntity> list, BaseApiClient client) throws Exception {
        ExTradeEffectCreditproductstatisticsSummaryRequest request = new ExTradeEffectCreditproductstatisticsSummaryRequest(list);
        StatisticsPostResponse postResponse = (StatisticsPostResponse) client.execute((AbstractApiRequest) request);
        return postResponse;
    }
}


/* Location:              D:\tuodayun\workspace\work\celoan-third-data-report-service-2.0.0-SNAPSHOT.jar!\BOOT-INF\classes\com\celoa\\util\DataReportUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */
